<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core">

    <h:body>
        <ui:composition template="/resources/template/template.xhtml">
            <ui:define name="content">
                <h:form>
                    <p:panel header="Search Bills" >
                        <f:facet name="header">
                            <h:panelGrid columns="6" >
                                <h:outputLabel value="From Date"/>
                                <p:calendar styleClass="dateTimePicker" id="fromDate" value="#{searchController.fromDate}" navigator="false" pattern="dd MMMM yyyy hh mm ss a" >      
                                </p:calendar>
                                <h:outputLabel value="To Date"/>
                                <p:calendar id="toDate" value="#{searchController.toDate}" navigator="false" pattern="dd MMMM yyyy hh mm ss a" >                                                                              
                                </p:calendar>
                                <p:commandButton id="btnSearch" ajax="false" value="Search" action="#{searchController.createPatientInvestigationsTable()}"/>
                                <p:commandButton id="btnSearch2" ajax="false" value="Search All" action="#{searchController.createPatientInvestigationsTableAll()}"/>
                                <p:spacer height="30"/><h:outputLabel/>
                                <h:outputLabel/><h:outputLabel/>
                                <h:outputLabel/> <h:outputLabel/>

                                <h:outputLabel value="Bill No"/>
                                <h:outputLabel value="Patient Name"/>
                                <h:outputLabel value="Patient Phone"/>                               
                                <h:outputLabel value="Investigation Value"/>
                                <h:outputLabel/><h:outputLabel/>
                                <p:inputText autocomplete="off"  value="#{searchController.searchKeyword.billNo}" />
                                <p:inputText autocomplete="off" value="#{searchController.searchKeyword.patientName}" />
                                <p:inputText autocomplete="off"  value="#{searchController.searchKeyword.patientPhone}" />
                                <p:inputText autocomplete="off" value="#{searchController.searchKeyword.itemName}"/>

                            </h:panelGrid>
                        </f:facet>
                        <p:defaultCommand target="btnSearch" />



                        <p:dataTable  id="tblBills" value="#{searchController.patientInvestigations}" var="pi"  >

                            <p:column headerText="Billing" styleClass="alignTop" >
                                <h:outputLabel value="Bill No : #{pi.billItem.bill.insId}" ></h:outputLabel>
                                <br/>
                                <h:outputLabel value="Name : #{pi.billItem.bill.patient.person.nameWithTitle}" >
                                </h:outputLabel>
                                <br/>
                                <h:commandLink value="(edit)" action="patient" style="text-decoration:underline;" >
                                    <f:setPropertyActionListener value="#{pi.billItem.bill.patient}" target="#{patientController.current}"/>
                                </h:commandLink>
                                <br/>
                                <h:outputLabel value="Age : #{pi.billItem.bill.patient.age},&nbsp;#{pi.billItem.bill.patient.person.sex}," >
                                </h:outputLabel>
                                <br/>
                                <h:outputLabel value="Phone : #{pi.billItem.bill.patient.person.phone}" >
                                </h:outputLabel>
                                <br/>
                                <h:outputLabel value="Billed From : #{pi.billItem.bill.institution.name}" ></h:outputLabel>
                            </p:column>

                            <p:column headerText="Investigation"  styleClass="alignTop" >
                                <h:outputLabel value="Ix : #{pi.billItem.item.name}" >
                                </h:outputLabel>
                                <br/>
                                <h:outputLabel value="Billed : " />
                                <h:outputLabel value="#{pi.billItem.bill.createdAt}" >
                                    <f:convertDateTime pattern="dd/MMM/yyyy - hh:mm:ss a"/>
                                </h:outputLabel>
                                <br/>
                                <h:outputLabel value="Sampled : " />
                                <h:outputLabel id="lblSample" rendered="#{pi.collected}" value="#{pi.sampledAt}" >
                                    <f:convertDateTime pattern="dd/MMM/yyyy - hh:mm:ss a"/>
                                </h:outputLabel>
                                <br/>
                                <h:outputLabel value="Received : " />
                                <h:outputLabel rendered="#{pi.received}" value="#{pi.receivedAt}" >
                                    <f:convertDateTime pattern="dd/MMM/yyyy - hh:mm:ss a"/>
                                </h:outputLabel>
                                <br/>
                                <h:panelGroup rendered="#{pi.billItem.bill.cancelled}" >
                                    <h:outputLabel style="color: red;" value="Cancelled : " />
                                    <h:outputLabel style="color: red;" rendered="#{pi.billItem.bill.cancelled}" value="#{pi.billItem.bill.cancelledBill.createdAt}" >
                                        <f:convertDateTime pattern="dd/MMM/yyyy - hh:mm:ss a"/>
                                    </h:outputLabel>
                                </h:panelGroup>
                                <h:panelGroup rendered="#{pi.billItem.refunded}" >
                                    <h:outputLabel style="color: red;" value="Refunded : " />
                                    <h:outputLabel style="color: red;" rendered="#{pi.billItem.refunded}" value="#{pi.billItem.referanceBillItem.bill.createdAt}" >
                                        <f:convertDateTime pattern="dd/MMM/yyyy - hh:mm:ss a"/>
                                    </h:outputLabel>
                                </h:panelGroup>
                                <br/>
                            </p:column>
                            <p:column  headerText="Actions"  styleClass="alignTop" >
                                <p:panelGrid columns="1" rendered="#{pi.billItem.bill.cancelled ne true and pi.billItem.refunded ne true }" >
                                    <p:commandButton process="btnSample" update="tblBills"  rendered="#{!pi.collected}"   id="btnSample" value="Collect Sample" action="#{patientInvestigationController.markAsSampled}" >
                                        <f:setPropertyActionListener value="#{pi}" target="#{patientInvestigationController.current}"></f:setPropertyActionListener>
                                    </p:commandButton>
                                    <p:commandButton process="btnReceive" update="tblBills"  rendered="#{pi.received ne true}"   id="btnReceive" value="Receive Sample" action="#{patientInvestigationController.markAsReceived()}" >
                                        <f:setPropertyActionListener value="#{pi}" target="#{patientInvestigationController.current}"></f:setPropertyActionListener>
                                    </p:commandButton>
                                    <p:commandButton ajax="false" id="btnPrintWorksheets" value="Worksheet" action="/lab/single_worksheet">
                                        <f:setPropertyActionListener value="#{pi}" target="#{patientInvestigationController.current}" ></f:setPropertyActionListener>
                                    </p:commandButton>
                                    <p:commandButton ajax="false" rendered="#{pi.received}" value="Result Entry" action="#{patientReportController.lastPatientReport(pi)}" >
                                        <f:setPropertyActionListener value="#{pi}" target="#{patientReportController.currentPtIx}"></f:setPropertyActionListener>
                                    </p:commandButton>
                                    <p:commandButton ajax="false" rendered="#{pi.received}" value="New Result" action="/lab/patient_report" actionListener="#{patientReportController.createNewReport(pi)}" >
                                        <f:setPropertyActionListener value="#{pi}" target="#{patientReportController.currentPtIx}"></f:setPropertyActionListener>
                                    </p:commandButton>
                                    <p:commandButton ajax="false" rendered="#{pi.received}" value="New Format" action="/lab/ix_for_ix" >
                                        <f:setPropertyActionListener value="#{pi}" target="#{patientReportController.currentPtIx}"></f:setPropertyActionListener>
                                        <f:setPropertyActionListener value="#{pi}" target="#{itemForItemController.patientIx}"></f:setPropertyActionListener>
                                    </p:commandButton>
                                </p:panelGrid>
                            </p:column>

                            <p:column headerText="Entered Reports"  styleClass="alignTop" >

                                <p:dataTable value="#{pi.patientReports}" var="dpr" rendered="#{pi.patientReports.size() ne 0}" >
                                    <p:column headerText="Actions">
                                        <p:commandLink style="text-decoration:underline;" value="To View / Edit / Approve / Print  " ajax="false" action="/lab/patient_report">
                                            <f:setPropertyActionListener value="#{dpr}" target="#{patientReportController.currentPatientReport}"></f:setPropertyActionListener>
                                        </p:commandLink>
                                    </p:column>
                                    <p:column headerText="Report">
                                        <h:outputLabel value="#{dpr.item.name}" >
                                        </h:outputLabel>
                                    </p:column>
                                    <p:column headerText="Data Entry at">
                                        <h:outputLabel value="#{dpr.dataEntryAt}" >
                                            <f:convertDateTime pattern="dd/MMM/yyyy - hh:mm:ss a"/>
                                        </h:outputLabel>
                                    </p:column>
                                    <p:column headerText="Approved at" >
                                        <h:outputLabel value="#{dpr.approveAt}" >
                                            <f:convertDateTime pattern="dd/MMM/yyyy - hh:mm:ss a"/>
                                        </h:outputLabel>

                                    </p:column>
                                    <p:column headerText="Printed at" >
                                        <h:outputLabel value="#{dpr.printingAt}" >
                                            <f:convertDateTime pattern="dd/MMM/yyyy - hh:mm:ss a"/>
                                        </h:outputLabel>
                                    </p:column>

                                </p:dataTable>
                            </p:column>
                        </p:dataTable>

                    </p:panel>

                </h:form>
            </ui:define>


        </ui:composition>

    </h:body>
</html>
